import request from '@/utils/request'

/**
 * @typedef Module - 终端基础信息的模块
 * @property {string} moduleCode
 * @property {number} moduleDurability
 * @property {Array} moduleList
 * @property {string} moduleName
 * @property {number} usageCount
 * @property {number} warmingCount
 */

export function getList(params) {
  return request({
    // url: '/vue-admin-template/terminal/list',
    url: '/online/management/operator/device',
    method: 'get',
    params
  })
}

export function deleteItem(data) {
  return request({
    url: `/online/management/operator/device/delete`,
    method: 'DELETE',
    data
  })
}

export function unbindTid(tid, devSn, data) {
  return request({
    url: `/online/management/operator/device/tid/${tid}/sn/${devSn}/unbind`,
    method: 'POST',
    data
  })
}

export function verifyBeforeUnbind(tid, devSn) {
  return request({
    url: `/online/management/operator/device/tid/${tid}/sn/${devSn}/unbind/verify`,
    method: 'POST'
  })
}

export function verifyBeforeDelete(devSn) {
  return request({
    url: `/online/management/operator/device/${devSn}/delete/verify`,
    method: 'GET'
  })
}

export function getRelations(devSn) {
  return request({
    url: `/online/management/operator/device/${devSn}/relations`,
    method: 'GET'
  })
}

export function bindTid(data) {
  return request({
    url: `/online/management/operator/device/tid/${data.devTid}/sn/${data.devSn}/bind`,
    method: 'POST',
    data
  })
}

export function exchangeDevice(devSn, newDevSn) {
  return request({
    url: `/online/management/estate/device/${devSn}/exchange/sn/${newDevSn}`,
    method: 'POST'
  })
}

export function activateDevice(data) {
  return request({
    url: `/online/management/operator/device/active`,
    method: 'POST',
    data
  })
}

export function getDetail(devSn) {
  return request({
    url: `/online/management/operator/device/${devSn}/detail`
  })
}

export function getHistoryCommands(devSn, params) {
  return request({
    url: `/online/management/operator/device/${devSn}/commands`,
    params
  })
}

export function lock(devSn) {
  return request({
    url: `/online/management/operator/device/${devSn}/remote-ctl/lock`,
    method: 'POST'
  })
}

export function batchLock(data) {
  return request({
    url: `/online/management/operator/device/remote-ctl/lock`,
    method: 'POST',
    data
  })
}

export function unlock(devSn) {
  return request({
    url: `/online/management/operator/device/${devSn}/remote-ctl/unlock`,
    method: 'POST'
  })
}

export function batchUnlock(data) {
  return request({
    url: `/online/management/operator/device/remote-ctl/unlock`,
    method: 'POST',
    data
  })
}

export function appList(devSn, params) {
  return request({
    url: `/online/management/operator/device/${devSn}/apps?moduleType=02`,
    params
  })
}

export function parameterAppList(devSn, params) {
  return request({
    url: `/online/management/operator/device/${devSn}/param-app`,
    params
  })
}

export function setParams(devSn, data) {
  return request({
    url: `/online/management/operator/device/${devSn}/remote-cli/params/system`,
    method: 'POST',
    data
  })
}

export function sendShutdownCommand(devSn, data) {
  return request({
    url: `/online/management/operator/device/${devSn}/remote-ctl/shutdown`,
    method: 'POST',
    data
  })
}

export function hardwareDetection(devSn, detectionMode) {
  return request({
    url: `/online/management/operator/device/${devSn}/remote-ctl/hardware-detection/${detectionMode}`,
    method: 'POST'
  })
}

export function realTimeMonitor(devSn) {
  return request({
    url: `/online/management/operator/device/${devSn}/remote-ctl/monitor/log`,
    method: 'POST'
  })
}

export function flyDesk(devSn) {
  return request({
    url: `/online/management/operator/device/${devSn}/remote-ctl/fly-desk`,
    method: 'POST'
  })
}

export function doRki(devSn) {

}

export function sendRestartCommand(devSn, data) {
  return request({
    url: `/online/management/operator/device/${devSn}/remote-ctl/reboot`,
    method: 'POST',
    data
  })
}

export function sendRevokeCommand(devSn, data) {
  return request({
    url: `/online/management/operator/device/${devSn}/remote-ctl/revoke`,
    method: 'POST',
    data
  })
}

export function sendRecoveryCommand(devSn) {
  return request({
    url: `/online/management/operator/device/${devSn}/remote-ctl/recovery`,
    method: 'POST'
  })
}

export function sendForceRecoveryCommand(devSn, isLock) {
  return request({
    url: `/online/management/operator/device/${devSn}/remote-ctl/force-recovery/lock/${isLock}`,
    method: 'POST'
  })
}

export function sendExtractLogCommand(devSn, data) {
  return request({
    url: `/online/management/operator/device/${devSn}/remote-ctl/extract/log`,
    method: 'POST',
    data
  })
}

export function sendFetchFileCommand(devSn, data) {
  return request({
    url: `/online/management/operator/device/${devSn}/remote-ctl/extract/file`,
    method: 'POST',
    data
  })
}

export function downloadOnlineParam(devSn, data) {
  return request({
    url: `/online/management/operator/device/${devSn}/remote-ctl/download/online-param`,
    method: 'POST',
    data
  })
}

export function collectAppInfo(devSn, data) {
  return request({
    url: `/online/management/operator/device/${devSn}/remote-ctl/info-upload`,
    method: 'POST',
    data
  })
}

export function terminalSync(devSn, data) {
  return request({
    url: `/online/management/operator/device/${devSn}/remote-ctl/sync`,
    method: 'POST',
    data
  })
}

export function sendCustomCommand(devSn, data) {
  return request({
    url: `/online/management/operator/device/${devSn}/remote-ctl/custom-cmd`,
    method: 'POST',
    data
  })
}

export function getDeviceLife(params) {
  return request({
    url: `/online/management/estate/device-life`,
    method: 'GET',
    params
  })
}

export function getGroupApp(devSn) {
  return request({
    url: `/online/management/operator/device/` + devSn + `/apps/group`,
    method: 'GET'
  })
}

export function getSysApp(devSn) {
  return request({
    url: `/online/management/operator/device/` + devSn + `/apps/system`,
    method: 'GET'
  })
}

export function checkApp(devSn) {
  return request({
    url: `/online/management/operator/device/` + devSn + `/app/check`,
    method: 'GET'
  })
}

export function checkFlyDeskApp(devSn) {
  return request({
    url: `/online/management/operator/device/` + devSn + `/app/check/flydesk`,
    method: 'GET'
  })
}

export function getThirdApp(devSn) {
  return request({
    url: `/online/management/operator/device/` + devSn + `/apps/third`,
    method: 'GET'
  })
}

export function runApp(devSn, appFileId) {
  return request({
    url: `/online/management/operator/device/` + devSn + `/app/` + appFileId + `/run`,
    method: 'POST'
  })
}

export function closeApp(devSn, pkgName) {
  return request({
    url: `/online/management/operator/device/` + devSn + `/app/` + pkgName + `/close`,
    method: 'POST'
  })
}

export function uninstallApp(devSn, pkgName) {
  return request({
    url: `/online/management/operator/device/` + devSn + `/app/` + pkgName + `/uninstall`,
    method: 'POST'
  })
}

export function installApp(devSn, appFileId) {
  return request({
    url: `/online/management/operator/device/` + devSn + `/remote-ctl/app-install/` + appFileId,
    method: 'POST'
  })
}

export function queryParamListByDevice(devSn) {
  return request({
    url: `/online/management/operator/cmp/device/${devSn}/param-list`,
    method: 'get'
  })
}

export function setDevAppParam(devSn, pkgName, config) {
  return request({
    url: `/online/management/operator/device/${devSn}/app/${pkgName}/param/${config}`,
    method: 'get'
  })
}

export function queryDeviceStatus(devSn) {
  return request({
    url: `/online/management/operator/device/${devSn}/status`,
    method: 'get'
  })
}

export function getCardTradeStatistics(devSn) {
  return request({
    url: `/online/management/operator/device/${devSn}/card`,
    method: 'get'
  })
}

export function getconvensionsStatistics(devSn, trendDays) {
  return request({
    url: `/online/management/operator/device/${devSn}/convensions/${trendDays}`,
    method: 'get'
  })
}

export function queryTrafficTrendStatistics(devSn, trendDays) {
  return request({
    url: `/online/management/operator/device/${devSn}/traffic/${trendDays}`,
    method: 'get'
  })
}

export function querySignalTrendStatistics(devSn, trendDays) {
  return request({
    url: `/online/management/operator/device/${devSn}/signal/${trendDays}`,
    method: 'get'
  })
}
export function querySignalTrendStatisticsByOperator(data) {
  return request({
    url: `/online/management/datacenter/device/trend/signal`,
    method: 'post',
    data
  })
}

export function queryDeviceTraffic(devSn) {
  return request({
    url: `/online/management/operator/device/${devSn}/traffic`,
    method: 'get'
  })
}

export function queryDeviceTags(devSn) {
  return request({
    url: `/online/management/operator/device/${devSn}/tag`,
    method: 'get'
  })
}

export function queryAllTags(params) {
  return request({
    url: `/online/management/operator/device/tag/list`,
    method: 'get',
    params
  })
}

export function addDeviceTag(devSn, data) {
  return request({
    url: `/online/management/operator/device/${devSn}/tag`,
    method: 'post',
    data
  })
}

export function delDeviceTag(devSn, devTagId) {
  return request({
    url: `/online/management/operator/device/${devSn}/tag/${devTagId}`,
    method: 'delete'
  })
}

export function getAppEvent(devSn, params) {
  return request({
    url: `/online/management/operator/device/${devSn}/app/event`,
    method: 'get',
    params
  })
}

export function getAppCombo(devSn, params) {
  return request({
    url: `/online/management/operator/device/${devSn}/app/combo`,
    method: 'get',
    params
  })
}
export function runtimeInfo(devSn, isSendCmd) {
  return request({
    url: `/online/management/operator/device/${devSn}/remote-ctl/runtime-upload/${isSendCmd}`,
    method: 'post'
  })
}

export function queryAppTrafficTrendStatistics(data) {
  return request({
    url: `/online/management/operator/device/${data.devSn}/apps/traffic`,
    method: 'POST',
    data
  })
}

/**
 * 请求终端基础信息中的模块数据
 * @param {string} devSn
 * @returns {Promise<Module[]>}
 */
export function queryModule(devSn) {
  return request({
    url: `/online/management/operator/device/${devSn}/module`,
    method: 'get'
  })
}

export function changeGeoTraceFlag(devSn, flag) {
  return request({
    url: `/online/management/operator/device/${devSn}/geo-trace-flag/${flag}`,
    method: 'post'
  })
}

export function getPassword(devSn) {
  return request({
    url: `/online/management/operator/device/${devSn}/password`,
    method: 'GET'
  })
}

export function fetchFileDirectory(devSn, data) {
  console.log(data)
  return request({
    url: `/online/management/operator/device/${devSn}/remote-ctl/fetch-directory`,
    method: 'POST',
    data: data
  })
}

export function getModelList(operatorId) {
  return request({
    url: `/online/management/operator/device/model-list/${operatorId}`,
    method: 'GET'
  })
}

export function getDeviceEvent(params) {
  return request({
    url: `/online/management/operator/device/event`,
    method: 'GET',
    params
  })
}

export function getDeviceConfig() {
  return request({
    url: `/online/management/operator/tid-config`,
    method: 'GET'
  })
}

export function getDeviceLanuage(params) {
  return request({
    url: `/online/management/operator/device/language`,
    method: 'GET',
    params
  })
}

export function getDeviceTimeZone(params) {
  return request({
    url: `/online/management/operator/device/time-zone`,
    method: 'GET',
    params
  })
}
